<?php

use Biz\service\springHomeDecActivity\WiningService;
use Biz\service\springHomeDecActivity\Util;

class SetDeliveryInfoAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;

    const VALIDATOR_TOAST_DEBUG = true;

    //参数校验-规则
    public const VALIDATOR_RULES = [
        'winning_record_id' => 'require|integer',
        'name' => 'require',
        'phone' => 'require',
    ];

    //参数校验-自定义消息
    public const VALIDATOR_MSG = [
        'winning_record_id.require' => '参数错误',
        'name.require' => '请输入姓名',
        'phone.require' => '请输入手机号',
    ];

    public function main()
    {
        $recordId = $this->params['winning_record_id'];
        $name = $this->params['name'];
        $phone = $this->params['phone'];
        $address = $this->params['address'] ?? '';
        $lockKey = 'spring_home_dec_act:set_delivery:' . $this->uid . ':' . $recordId;
        Util::lockSubmit($lockKey);
        $nResult = WiningService::setDeliveryInfo($this->uid, $recordId, $name, $phone, $address);
        if (!$nResult) {
            throw new \Exception("设置失败", self::CODE_ERROR_VIEW_TOSTA);
        }
        $this->setSuccess('success');
    }
}